package com.wr.springbootRabbitMq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitmq配置类
 */
@Configuration
public class RabbitMqDirectConfig {

    // 1、声明交换机
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("direct-order-exchange");
    }

    //2、声明队列
    @Bean
    public Queue smsDirectQueue(){
        return new Queue("sms.direct.queue");
    }
    @Bean
    public Queue emailDirectQueue(){
        return new Queue("email.direct.queue");
    }
    @Bean
    public Queue duanxinDirectQueue(){
        return new Queue("duanxin.direct.queue");
    }

    //3、绑定交换机与队列

    @Bean
    public Binding smsDirectBinding(){
        return BindingBuilder.bind(smsDirectQueue()).to(directExchange()).with("sms");
    }
    @Bean
    public Binding emailDirectBinding(){
        return BindingBuilder.bind(emailDirectQueue()).to(directExchange()).with("email");
    }
    @Bean
    public Binding duanxinDirectBinding(){
        return BindingBuilder.bind(duanxinDirectQueue()).to(directExchange()).with("duanxin");
    }
}
